package com.qezhhnjy.mall.order.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.order.OrderReturnReason;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.order.service.OrderReturnReasonService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 退货原因 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "退货原因接口")
@Slf4j
@RequestMapping("/order-return-reason")
public class OrderReturnReasonController {
    @Resource
    private OrderReturnReasonService orderReturnReasonService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取退货原因信息")
    public BaseResult<OrderReturnReason> get(Long id) {
        OrderReturnReason orderReturnReason = orderReturnReasonService.getById(id);
        return BaseResult.success(orderReturnReason);
    }

    @PostMapping("/save")
    @Operation(summary = "新增退货原因信息")
    public BaseResult<OrderReturnReason> save(@RequestBody OrderReturnReason orderReturnReason) {
        orderReturnReasonService.save(orderReturnReason);
        return BaseResult.success(orderReturnReason);
    }

    @PutMapping("/update")
    @Operation(summary = "更新退货原因信息")
    public BaseResult<OrderReturnReason> update(@RequestBody OrderReturnReason orderReturnReason) {
        orderReturnReasonService.updateById(orderReturnReason);
        return BaseResult.success(orderReturnReason);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取退货原因信息")
    public BaseResult<Page<OrderReturnReason>> page(@RequestBody Page<OrderReturnReason> page) {
        orderReturnReasonService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除退货原因信息")
    public BaseResult<Long> delete(Long id) {
        orderReturnReasonService.removeById(id);
        return BaseResult.success(id);
    }
}

